/**
 * @file    app_sample.c
 * @brief   用户任务-采样任务
 * @author  Liuwei
 * @version 1.0.1
 * @date    2023-04-27
 * 
 * @copyright Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version   <th>Author   <th>Description
 * <tr><td>2023-04-27 <td>1.0.1     <td>Liuwei   <td>首次创建
 * </table>
 */

/* includes ------------------------------------------------------------------*/
#include "app_sample.h"
#include "FreeRTOS.h"
#include "task.h"
#include "sample.h"
#include "sop_calc.h"
#include "dev_afe.h"
#include "app_monitor.h"
/* macro/define --------------------------------------------------------------*/
#define APP_SAMPLE_TASK_CYCLE             (50) 

/* typedef -------------------------------------------------------------------*/

/* local functions -----------------------------------------------------------*/

/* static variables ----------------------------------------------------------*/
static uint8_t sample_once_cmp = FALSE;
/* global variables ----------------------------------------------------------*/

/** ------------------------------------------------------------------------- *
  *                             Global function
 ** ------------------------------------------------------------------------- */
/**
 * @brief 系统监控任务
*/
void vAppSampleTask(void *pvParameters)
{
	uint32_t task_cycle = 0;
	
    portTickType xLastExecutionTime;
    xLastExecutionTime = xTaskGetTickCount();

    sample_init();
	
	sample_once_cmp = FALSE;
	
	task_run_reset(TASK_ID_SAMPLE);
	
    while(1)
    { 
		task_cycle = task_get_cycle(TASK_ID_SAMPLE);
		if(task_cycle > 50 * APP_SAMPLE_TASK_CYCLE)
			task_cycle = APP_SAMPLE_TASK_CYCLE;
		
		sample_volt();
		
		sample_curr(task_cycle);
		
        sample_afe_deal(task_cycle);
		
		sample_fault_clear(task_cycle);
		
		sample_balance_ctrl();
		
        sample_temp();
		
		sample_once_cmp = TRUE;
		
		task_run_count(TASK_ID_SAMPLE);
        
        vTaskDelayUntil( &xLastExecutionTime, APP_SAMPLE_TASK_CYCLE );
    }
}

uint8_t sample_complete(void)
{
	return sample_once_cmp;
}
/** ------------------------------------------------------------------------- *
  *                              Local function
 ** ------------------------------------------------------------------------- */

/********** Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD *********/


